home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 1.8 KB | 91 lines | [TEXT/MSET] |
- \ 28Oct94 dbh removed addr: references
-
- (*
- Class $16 is a dictionary-based simple string class whose length may vary,
- but the maximum length is 16.
-
- $16's are nice for use as string ivars, or if you want a persistent string
- object in the dictionary (no handles here so we don't need to do a new:
- and restore the data at each runtime).
-
- *)
-
-
- :class $16 super{ object }
- byte length
- 16 bytes text
-
- :m limit: ( -- lim )
- 16 ;m
-
- :m size: \ ( -- len)
- get: length ;m \ addr: will get the address of the indexed Width
- \ here we use width area to store the string length
-
- private \ private because we should never do this directly
-
- :m setsize: \ ( len --)
- dup limit: self > abort" No more room in $16."
- put: length
- ;m
- public
-
- :m addr: \ ( -- addr) \ redefine to give us the indexed data area
- text ;m
-
- :m put: { addr len -- }
- len setsize: self
- addr ( src) addr: self ( dest) len ( cnt) cmove ;m
-
- :m get: ( -- addr len )
- addr: self size: self ;m
-
- :m print:
- get: self type ;m
-
- :m clear:
- 0 setsize: self ;m
-
- :m classinit:
- clear: self ;m
-
- :m put$: { $ptr -- }
- $ptr 1 + $ptr c@ put: self ;m
-
- :m get$: \ ( -- $ptr )
- length ;m
-
- :m add: { addr len \ $len -- }
- size: self -> $len
- len $len + setsize: self
- addr ( src) addr: self $len + ( dest) len ( cnt) cmove ;m
-
- :m add$: { $ptr -- }
- $ptr 1 + $ptr c@ add: self ;m
-
- :m uc: ( -- ) \ converts to upper case and does not get it
- get: self upper ;m
-
- :m +: ( c -- ) \ appends a char to the end of the string
- pad c! pad 1 add: self ;m
-
- :m clip: { n -- } \ remove n characters from end of string
- \ if n is too large, string is just cleared with no error
- size: self n - 0 max setsize: self ;m
-
- ;class
-
- endload
-
- *** EXAMPLE USE
-
- 7 $16 jj
- print: jj
- size: jj .
- 3 clip: jj
- " hello" put: jj
- " ff" add: jj
- uc: jj type
- 32 +: jj
-
-